package com.oa.tools.utils.oa;

import java.io.IOException;
import java.io.InputStream;

public class DecryptionInputStream extends AbstractInputStream
{
  private boolean noEncryption;

  public DecryptionInputStream(InputStream originStream)
    throws IOException
  {
    super(originStream);
  }

  public DecryptionInputStream(InputStream originStream, int encryptionMode) throws IOException
  {
    super(originStream, encryptionMode);
  }

  protected void init()
    throws IOException
  {
    this.noEncryption = (this.cryptionMode == 0);
    if (this.noEncryption) {
      return;
    }
    int len = markBytes.length;

    byte[] b = new byte[len];
    int count = this.originStream.read(b);
    if (count > 0)
      for (int i = 0; i < len; i++)
        if (format(b[i] + 128) != markBytes[i] + 128) {
          this.additionalBytes = b;
          this.noEncryption = true;
          return;
        }
  }

  protected void format(byte[] b, int off, int len)
  {
    if (this.noEncryption)
      return;
    for (int i = off; i < len; i++)
      if (b[i] == -128) {
        b[i] = 127;
      }
      else
      {
        int tmp35_33 = i;
        byte[] tmp35_32 = b; tmp35_32[tmp35_33] = ((byte)(tmp35_32[tmp35_33] - 1));
      }
  }

  protected int format(int i)
  {
    if (this.noEncryption)
      return i;
    if (i == -1)
      return -1;
    if (i == 0)
      return 255;
    return i - 1;
  }
}